require 'prawn'
require 'prawn/table'
require_relative 'lib/prawn/my_helpers'
::Prawn::Document.extensions << Prawn::MyHelpers
Prawn::Document.generate("implicit.pdf") do |pdf|
  pdf.font "./assets/fonts/SimHei.ttf"
  pdf.repeat(:all) do
    # set the header
    pdf.my_logo_header

    # set the footer
    pdf.my_footer_with_address
  end

  pdf.bounding_box([0, 664], :width => 520, :height => 620) do
    # pdf.default_leading 1
    # pdf.font_size 11
    # pdf.font "./assets/fonts/SimHei.ttf"
    data = [ ['病人/Patient', '送检医生/Physician', '标本资料/Specimen'],
             ['名字/Name: 李敏', '名字/Name: 武永拴', '病理号/Acc\'n #: 471-19-08549'],
             ['年龄/Age: 49','单位/Client: 和林县医院', '取材日期/DOS: 2019-11-13']]
    pdf.table(data, :column_widths => [170, 170, 170], :cell_style => { :font => "./assets/fonts/SimHei.ttf", :border_color => 'CCCCCC', :border_width => 1, :inline_format => true }) do
      # row(0).font_style = :bold
      # row(0).border_bottom_color = '333333'
    end

    pdf.move_down 20
    # pdf.text "<b>标本名称:</b>   胃窦前壁", :inline_format => true
    pdf.text "标本名称:   胃窦前壁", :inline_format => true
    pdf.stroke_color "CCCCCC"
    pdf.stroke do
      pdf.move_down 20
      pdf.horizontal_rule
    end

    pdf.move_down 20
    pdf.text "病理诊断:"
    pdf.move_down 20

    pdf.indent(20) do
      pdf.text "胃窦前壁 (Anterior antral wall), 活检 (Biopsy):"
      pdf.indent(20) do
        pdf.move_down 20
        pdf.draw_text "-", :at => [0, pdf.cursor.to_i]
        pdf.draw_text "胃窦部粘膜伴轻度浅表性慢性非萎缩性胃炎,伴黄瘤 。", :at => [20, pdf.cursor.to_i]
        pdf.indent(20) do
          pdf.move_down 20
          pdf.text "未见肠上皮化生或异型增生。"
          pdf.move_down 20
          pdf.text "Gastric antral type mucosa with mild chronic inflammation and xanthoma, negative for intestinal metaplasia or dysplasia."
        end
      end
    end
    pdf.move_down 20
    pdf.text "显微镜图像:"
    pdf.image "./assets/images/microscope.jpeg", :position => :center, :scale => 0.5
    pdf.move_down 20
    pdf.text "大体所见:"
    pdf.move_down 20
    pdf.text "收到福尔马林固定的淡黄 色组织 1块, 大小为0.3 x0.2 x0.1 cm,全部送检于A."
    pdf.move_down 10

  end
end
